package com.bolt.gateway.utils;

import com.bolt.common.utils.StrUtil;
import org.springframework.http.server.reactive.ServerHttpRequest;

import java.util.List;

public class TokenUtil {
    public  static String extractToken(ServerHttpRequest request) {
        List<String> strings = request.getHeaders().get("Authorization");
        String authToken = "";
        if (strings != null) {
            authToken = strings.get(0).substring("Bearer".length()).trim();
        }

        if (StrUtil.isBlank(authToken)) {
            strings = request.getQueryParams().get("access_token");
            if (strings != null) {
                authToken = strings.get(0);
            }
        }

        return authToken;
    }
}

 